fondle unicsv header detection some more.
authortsteven4 <tsteven4@gmail.com>
Fri, 13 Jun 2014 23:29:35 +0000 (23:29 +0000)
committertsteven4 <tsteven4@gmail.com>
Fri, 13 Jun 2014 23:29:35 +0000 (23:29 +0000)
this seems like a step backwards, but we cover another error and provide a test case.

gpsbabel/reference/headerdetection.unicsv [new file with mode: 0644]
gpsbabel/testo.d/unicsv.test
gpsbabel/unicsv.cc

diff --git a/gpsbabel/reference/headerdetection.unicsv b/gpsbabel/reference/headerdetection.unicsv
new file mode 100644 (file)
index 0000000..110c4fc
--- /dev/null
@@ -0,0 +1,6 @@
+name   lat     lon     ele Ft  depth   temp    heart   caden
+Lickskillet    40.075297       -105.414373     7526.2467191601         20      60      85
+Gold Hill      40.063311       -105.409614     8248.031496063          18      160     45
+Barker Reservoir Dam   39.966120       -105.482821     8198.8188976378 37              50      
+Barker Reservoir Shore 39.962905       -105.502236     8198.8188976378 0               40      
+James Peak     39.852048       -105.690364     13330.0524934383                0       70      
index 0e17f66a5186a0ba71093030068687ba760672b8..f84aae2745ded4b0c80b8a322669c5767e28b772 100644 (file)
@@ -14,3 +14,7 @@ compare ${REFERENCE}/garmin_txt-uni.csv ${TMPDIR}/garmin_txt-uni.csv
 gpsbabel -i gpx -f ${REFERENCE}/gc/GC7FA4.gpx -o unicsv,utc=0 -F ${TMPDIR}/gcunicsv-1.csv
 gpsbabel -i unicsv,utc=0 -f ${REFERENCE}/gc/GC7FA4~unicsv.csv -o unicsv,utc=0 -F  ${TMPDIR}/gcunicsv-2.csv
 compare ${TMPDIR}/gcunicsv-1.csv ${TMPDIR}/gcunicsv-2.csv
+
+# check header detection features
+gpsbabel -i unicsv,utc=0 -f ${REFERENCE}/headerdetection.unicsv -x transform,trk=wpt -o gpx,garminextensions -F ${TMPDIR}/headerdetection~unicsv.gpx
+compare ${TMPDIR}/headerdetection~unicsv.gpx ${REFERENCE}/extensiondata~unicsv.gpx
index 238e398c6ee0637c3a24ad7689c513772239b423..2a63ff890ce5ff1202c77dc53f36572999cca047 100644 (file)
@@ -519,11 +519,12 @@ unicsv_compare_fields(const QString& s, const field_t* f)
 
 
 static void
-unicsv_fondle_header(char* ibuf)
+unicsv_fondle_header(const char* ibuf)
 {
   // TODO: clean up this back and forth between QString and char*.
-  QString s;
+  QString s = QString(ibuf);
   char* buf = NULL;
+  char* cbuf_start = NULL;
   int column;
   const cet_cs_vec_t* ascii = &cet_cs_vec_ansi_x3_4_1968;      /* us-ascii */
 
@@ -531,7 +532,6 @@ unicsv_fondle_header(char* ibuf)
    * If we see a tab in that header, we decree it to be tabsep.
    */
   unicsv_fieldsep = ",";
-  s = QString(ibuf); // main has set the codec to UTF-8.
   if (s.contains('\t')) {
     unicsv_fieldsep = "\t";
   } else if (s.contains(';')) {
@@ -539,21 +539,22 @@ unicsv_fondle_header(char* ibuf)
   } else if (s.contains('|')) {
     unicsv_fieldsep = "|";
   }
-  s = s.toLower();
+  cbuf_start = xstrdup(CSTR(s.toLower()));
+  const char* cbuf = cbuf_start;
 
   /* convert the header line into native ascii */
   if (global_opts.charset != ascii) {
-    buf = cet_str_any_to_any(CSTR(s), global_opts.charset, ascii); // CSTR goes back to UTF-8.
-    ibuf = buf;
+    buf = cet_str_any_to_any(cbuf, global_opts.charset, ascii);
+    cbuf = buf;
   }
 
   column = -1;
-  while ((s = csv_lineparse(ibuf, unicsv_fieldsep, "\"", 0)) , !s.isEmpty()) {
+  while ((s = csv_lineparse(cbuf, unicsv_fieldsep, "\"", 0)) , !s.isEmpty()) {
     s = s.trimmed();
 
     field_t* f = &fields_def[0];
 
-    ibuf = NULL;
+    cbuf = NULL;
     column++;
     unicsv_fields_tab_ct++;
 
@@ -594,6 +595,9 @@ unicsv_fondle_header(char* ibuf)
   if (buf) {
     xfree(buf);
   }
+  if (cbuf_start) {
+    xfree(cbuf_start);
+  }
 }
 
 static void